<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--部门数据-->
            <el-col :span="4" :xs="24">
                <fileTrees @handleNodeClick="onTreeClick" :tableHeight="treeHeight" :isnoClick="isnoClick" :menuId="menuId">
                </fileTrees>
            </el-col>
            <!--离线接收数据-->
            <el-col :span="20" :xs="24" v-show="isShow">
                <queryCriteriaList v-if="listFrom.length > 0" :showSearch="showSearch" :listFrom="listFrom"
                    @resetQuery="resetQuery" @handleQuery="handleQuery" ref="queryForm"></queryCriteriaList>
                <el-row :gutter="10" class="mb8" ref="refbut">
                    <el-col :span="1.5"
                        v-show="(subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 1) || (subStr == 'X' && categoryType == 3)">
                        <el-button type="danger" plain icon="el-icon-takeaway-box" @click="tuihuiTap">退回</el-button>
                    </el-col>
                    <el-col :span="1.5"
                        v-show="(subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 1) || (subStr == 'X' && categoryType == 3)">
                        <el-button type="danger" plain icon="el-icon-takeaway-box"  v-hasPermi="['archive:dagl:zipTap']" @click="zipTap">打包</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="info" plain icon="el-icon-download" @click="handleExport"
                            v-hasPermi="['archive:dagl:export']">导出</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-plus" @click="handleSpecalTap"
                            v-hasPermi="['archive:da:library']">添加到档案资源</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'V' || subStr == 'F'">
                        <el-button type="primary" plain icon="el-icon-plus" @click="handleGuidanceTap()"
                            v-hasPermi="['archive:supervisionDa:fileManagement']">添加到指导单</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'F'">
                        <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:da:fileMldy']"
                            @click="printTap()">目录打印</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'V'">
                        <el-button type="primary" plain icon="el-icon-printer" v-hasPermi="['archive:da:folderMldy']"
                            @click="printTap()">目录打印</el-button>
                        <el-button type="warning" plain icon="el-icon-printer" v-hasPermi="['archive:da:folderFileMldy']"
                            @click="printTap(1)">卷内目录打印</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'X'">
                        <!-- <el-button type="primary" plain icon="el-icon-printer"
                            @click="printTap()">目录打印</el-button> -->
                        <!-- <el-button type="warning" plain icon="el-icon-printer"
                            @click="printTap()">卷内目录打印</el-button> -->
                        <el-button type="success" plain icon="el-icon-printer" v-hasPermi="['archive:da:itemMldy']"
                            @click="printTap()">项目目录打印</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" plain icon="el-icon-takeaway-box" v-hasPermi="['archive:da:fengmian']"
                            @click="printDyTap(0)">封面打印</el-button>
                    </el-col>

                    <el-col :span="1.5">
                        <el-button type="primary" plain icon="el-icon-takeaway-box" v-hasPermi="['archive:da:beikaobiao']"
                            @click="printDyTap(1)">备考表打印</el-button>
                    </el-col>

                    <el-col :span="1.5" v-show="subStr == 'V'">
                        <el-button type="warning" plain icon="el-icon-printer" @click="printDyTap(2)"
                            v-hasPermi="['archive:da:heji']">打印盒脊</el-button>
                    </el-col>

                    <el-col :span="1.5"
                        v-show="(subStr == 'V' && categoryType == 1) || (subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 3)">
                        <el-button type="primary" icon="el-icon-folder-opened" @click="boxingTap"
                            v-hasPermi="['archive:box:saveBox']">装盒</el-button>
                    </el-col>
                    <el-col :span="1.5"
                        v-show="(subStr == 'V' && categoryType == 1) || (subStr == 'F' && categoryType == 0) || (subStr == 'V' && categoryType == 3)">
                        <el-button type="primary" icon="el-icon-folder" v-hasPermi="['archive:box:cancelBox']"
                            @click="quxiaoBoxingTap">取消装盒</el-button>
                    </el-col>

                    <el-col :span="1.5"
                        v-show="(subStr == 'V' && categoryType == 1) || (subStr == 'F' && categoryType == 0) || (subStr == 'X' && categoryType == 3)">
                        <el-button type="primary" icon="el-icon-plus" @click="addTransferOrderTap"
                            v-hasPermi="['manage:yijiao:addHandOverDa']">移交单</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'V' && categoryType == '3'">
                        <!-- v-hasPermi="['archive:lxjs:updateBgqx']" -->
                        <el-button type="danger" plain icon="el-icon-takeaway-box" @click="tuihuiTap(1)"
                            v-hasPermi="['archive:da:tuihuiAnJuan']">退回</el-button>
                    </el-col>
                    <el-col :span="1.5" v-show="subStr == 'F'">
                        <el-button type="danger" plain icon="el-icon-takeaway-box" @click="HJhaoTap" v-hasPermi="['archive:hjh:button']">关联关系</el-button>
                    </el-col>
                    <right-toolbar :showSearch.sync="showSearch" @queryTable="queryTableTap"></right-toolbar>
                </el-row>
                <tableList v-if="tableHeight" :tableHeaderList="tableHeaderList"
                    @handleSelectionChange="handleSelectionChange" :tableData="tableData" :loading="loading"
                    :tableHeight="tableHeight" @celldblclick="celldblclick" @sortChange="sortChange" ref="ref"></tableList>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize" @pagination="getlistPost" />
            </el-col>

            <el-col :span="20" :xs="24" v-show="!isShow" class="empty">
                <el-empty :image-size="200"></el-empty>
            </el-col>

        </el-row>
        <!-- start 组件著录、修改 -->
        <jiandeit v-if="jianOpen" :open="jianOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
            @submitDetail="submitDetail" :isParams="1">
        </jiandeit>
        <!-- end  组件著录、修改-->

        <!-- start 组卷著录、修改 -->
        <juandeit v-if="juanOpen" :open="juanOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
            @submitDetail="submitDetail" :isParams="1"></juandeit>
        <!-- end  组卷著录、修改-->

        <!-- start 项目著录  修改 -->
        <projectdeit v-if="projectOpen" :open="projectOpen" :openInfo="openInfo" @submitDetail="submitDetail"
            @closeDelDialog="closeDelDialog" :isParams="1"></projectdeit>
        <!-- end 项目著录、修改 -->

        <!--start  组件详情 -->
        <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose">
        </jianDetailsOpen>
        <!--end 组件详情 -->
        <!-- start 组卷\项目详情 -->
        <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData"
            @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
        <!-- end 组卷\项目详情 -->
        <!-- start  目录打印 -->
        <vPrint v-if="printOpen" :open="printOpen" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderList"
            :printList="printList"></vPrint>
        <!-- end  目录打印 -->
        <!-- start  卷内目录打印 -->
        <vPrint v-if="printOpenV" :open="printOpenV" @closeDelDialog="closeDelDialog" :tableHeaderList="tableHeaderListV"
            :printList="printListV"></vPrint>
        <!-- end   卷内目录打印 -->


        <!-- start 装盒 -->
        <vBoxing v-if="boxingOpen" :open="boxingOpen" :queryParams="queryParams" :ids="ids" :list="dataStr"
            @closeDelDialog="closeDelDialog" :boxType="boxType" :categoryType="categoryType" :permitInfo="permitInfo"
            @submitTap="submitTap"></vBoxing>
        <!-- end 装盒 -->


          <!--start 互见号  hjhaoType==1 '档案整理'  hjhaoType==2 '（目录检索，全文检索）'-->
          <hjhao v-if="hjhaoOpen" :open="hjhaoOpen" :hjhaoType="1"  @closeDelDialog="closeDelDialog" :daId="ids" :menuId="menuId"></hjhao>
        <!-- end 互见号 -->
    </div>
</template>
<script>
import {
    getqueryfieldList,
    getlistbytreenodeList,
    getthbytreenodeHeaderList,
    geturl,
    getbkbdata,
    supervisionDa1
} from "@/api/archive/fileCollection/offlinReception.js";
import {
    tuihui,
    addHandOverDa,
    isPermit,
    getFlag,
    cancelBox,
    getmultipleInfo,
    tuihuiAnJuan,
    pack
} from "@/api/archive/filesManage/filesManageMenu.js" //档案管理
import queryCriteriaList from "@/components/queryCriteriaList/index.vue"  //查询列表
import fileTrees from "@/components/fileTrees/index.vue"  //档案树
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import tableList from "@/components/tableList/index.vue"
import jiandeit from "@/views/archive/fileCollection/offlinReception/jiandeit.vue" //件添加修改弹窗
import juandeit from "@/views/archive/fileCollection/offlinReception/juandeit.vue" //卷添加修改弹窗
import projectdeit from "@/views/archive/fileCollection/offlinReception/projectdeit.vue" //卷添加修改弹窗
import treeHeight from '@/mixins/treeHeight'//计算左侧树的高度
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情'
import vPrint from "@/components/printComponent/index.vue" //目录打印弹窗模板
import vBoxing from "@/views/archive/filesManage/filesManageMenu/boxingTem.vue" //装盒弹出窗
import { getLastIndexOf } from "@/utils/index.js"
import { addPerson } from "@/api/archive/bianyan/archiveResources";
import { getTypeObject } from '@/api/archive/dict/dictManageData'
import hjhao from "@/views/archive/filesManage/filesManageMenu/hjhao/index.vue"
export default {
    mixins: [treeHeight], // 混入方法
    archive_Dicts: ['MJ', 'BGQX', 'IS_OPENS', 'CSLY'],
    components: {
        queryCriteriaList,
        fileTrees,
        jiandeit,
        juandeit,
        tableList,
        projectdeit,
        jianDetailsOpen,
        juanDetailsOpen,
        vPrint,
        vBoxing,
        hjhao
    },
    data() {
        return {
            isnoClick: true,
            scroll: "",
            loading: false,
            // 显示搜索条件
            showSearch: true,
            listFrom: [], //查询框列表
            isShow: false, //是否显示右侧数据
            categoryinfo: "", //档案门类回显信息
            total: 0,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            tableHeaderList: [], //table表头数据
            tableHeaderListV: [], //卷内目录table表头数据
            tableData: [],//table列表数据
            jianOpen: false, //组件打开关闭
            juanOpen: false, //组卷打开关闭
            projectOpen: false,//项目打开关闭
            jianDetailsOpen: false,//件详情弹窗
            juanDetailsOpen: false,//卷详情弹窗
            openInfo: { //件 卷  项目
                opens: false,
                categoryId: undefined,
                menuId: undefined,
                type: undefined
            },
            tableHeight: "",
            ids: undefined,
            detail: [],
            single: true,
            multiple: true,
            rowList: "", //当前点击的数据
            subStr: "",  //获取点击当前树的 件 卷  项目 截取 sub_table_name显示
            categoryType: '',
            printOpen: false, //打印弹出窗
            printOpenV: false, //卷内目录打印
            boxingOpen: false, //装盒弹窗
            boxType: "", //判断装盒是卷还是件
            categoryInfo: "",//档案门类树门类根据categoryID回显门类详情 根据 storeMode 判断是否可以装盒  storeMode==0，盒   storeMode==1，卷
            permitInfo: "",
            printList: [],
            printListV: [],
            dataStr: [],
            menuId: '',
            hjhaoOpen:false,
        }
    },

    created() {
        this.menuId = this.$route.meta.menuId
    },


    methods: {
        //动态设置table的高度
        tableHeightData() {
            this.$nextTick(
                () => {
                    let h = document.documentElement.clientHeight
                    //     console.log(this.$refs.queryForm.$el.offsetHeight, this.$refs.refbut.$el.offsetHeight, "sdklfjklliuhaiorng")
                    h = h - 200
                    if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
                        h = h - this.$refs.queryForm.$el.offsetHeight
                    }

                    if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
                        h = h - this.$refs.refbut.$el.offsetHeight
                    }
                    // console.log(h,"sdjfdklsjfkl")
                    this.tableHeight = h > 310 ? h : 310 // 根据自己项目定高度
                    return h
                }
            )

        },

        // 树节点单击事件
        onTreeClick(data) {
            console.log(data, "+++")

            /*getGroupTree(data.categoryId).then(response => {
                this.categoryInfo = response.data
            });*/
            this.isnoClick = false
            this.treeRowData = data;
            if (data.categoryId != null) {
                this.isShow = true
            } else {
                this.isShow = false
            }
            if (this.$refs.queryForm != undefined) {
                this.$refs.queryForm.queryParams = {};
            }
            if (data.nodeType == null || data.nodeType == "t" || data.nodeType == "f") {
                this.isnoClick = true;
                return false;
            }
            getGroupTree(data.categoryId).then(response => {
                this.categoryInfo = response.data
            });
            this.loading = true;
            this.queryParams = data;
            this.queryParams.state = 5;
            // this.queryParams.jsType = 1;
            this.queryParams.pageNum = 1;
            this.queryParams.pageSize = 10;
            this.queryParams.order = '';
            if (this.queryParams.sub_table_name != undefined) {
                this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
                let stb = this.queryParams.sub_table_name;
                let stbArr = stb.split("_");
                this.categoryType = stbArr[stbArr.length - 3];
            } else {
                this.getGroupTreePost(data.categoryId);
            }
            this.getqueryfieldListPost();//点击树节点获取查询字段
            this.getlistHeaderPost();/**点击树节点,获取table表头数据 */
            this.$refs.ref.clearSort()
        },

        //档案门类树门类根据categoryID回显
        getGroupTreePost(ID) {
            getGroupTree(ID).then(response => {
                if (response.data.type == "0") { //件
                    this.queryParams.sub_table_name = response.data.fileTableName;
                } else if (response.data.type == "1") { //卷
                    this.queryParams.sub_table_name = response.data.folderTableName;
                } else { //项目
                    this.queryParams.sub_table_name = response.data.itemTableName;
                }
                this.subStr = getLastIndexOf(this.queryParams.sub_table_name);
                let stb = this.queryParams.sub_table_name;
                let stbArr = stb.split("_");
                this.categoryType = stbArr[stbArr.length - 3];
            });
        },



        /** 点击树节点获取查询字段 */
        getqueryfieldListPost(data) {
            getqueryfieldList({
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                subTableName: this.queryParams.sub_table_name,

            }).then(response => {
                this.listFrom = response.rows;
            });
        },
        /**点击树节点,获取table表头数据 */
        getlistHeaderPost() {
            this.queryParams.searchcolumn = undefined
            getthbytreenodeHeaderList({
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                subTableName: this.queryParams.sub_table_name
            }
            ).then(response => {
                this.tableHeaderList = response.rows;
                var fields = []
                for (var i in response.rows) {
                    fields.push(response.rows[i].FIELD_NAME)
                }
                this.queryParams.fields = fields.toString();


                //获取指定字典列表
                var headerlist = [];
                for (var i = 0; i < this.tableHeaderList.length; i++) {
                    if (this.tableHeaderList[i].SHOWTYPE.toString().indexOf('5') != -1) {
                        this.tableHeaderList[i].SHOWTYPE = 5
                    }
                    if (this.tableHeaderList[i].SHOWTYPE == 5) {
                        // console.log(this.tableHeaderList[i])
                        headerlist.push(this.tableHeaderList[i].FIELD_NAME)
                    }
                }
                // console.log(headerlist,"++++")
                if (headerlist.length > 0) {
                    getTypeObject(headerlist).then((res) => {
                        this.dictList = res.data;
                    })
                }
                this.getlistPost();
                this.isnoClick = true;
            });
        },
        /** 点击树节点,获取table数据*/
        getlistPost() {
            if (this.queryParams.fields==''){
              this.$message({ message: '请先对该门类进行配置！', type: 'warning' })
              return ;
            }
            getlistbytreenodeList(this.queryParams).then(response => {
                this.tableData = response.rows;
                this.total = response.total;
                this.loading = false;
                this.tableHeightData();
                // this.isnoClick = true;
            });
        },

        //是否选择数据
        handleSelectionChange(ids, single, multiple, selection) {
            this.ids = ids.toString();
            this.single = single;
            this.multiple = multiple;
            console.log(selection)
            this.detail = selection.map(item => {
                return {
                    daDh: item.DH,
                    daBgqx: item.BGQX,
                    daMj: item.MJ,
                    daId: item.ID,
                    daTitle: item.TITLE == undefined ? item.XMMC : item.TITLE,
                    daNd: item.ND
                }
            });
        },

        //表单重置
        resetQuery() {
            this.queryParams.searchcolumn = undefined
            this.queryParams.order = undefined;
            this.$refs.ref.clearSort()
            this.getlistPost();
        },
        //点击搜索
        handleQuery(searchcolumn) {
            var column = searchcolumn.filter(item => { return item.value !== '' && item.value !== null })
            this.queryParams.searchcolumn = column
            this.queryParams.order = undefined;
            this.$refs.ref.clearSort()
            this.getlistPost();
        },
        //刷新页面
        queryTableTap() {
            this.queryParams.order = undefined;
            this.getlistPost();
            this.$refs.ref.clearSort()
        },

        //给项目案卷著录
        handledeitanJuanTap() {
            this.openInfo = {
                opens: true,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                type: 1, //传卷类型  0,组件 1，组卷 3，项目
                folderId: undefined, //组卷id
                itemId: undefined, //项目Id
                subTableName: this.queryParams.sub_table_name
            }
            console.log(this.openInfo)
            if (this.ids == undefined) {
                this.$message({ message: '请选择先选择数据哦', type: 'warning' })
                return false
            }
            if (this.single) {
                this.$message({ message: '请选择一条数据哦', type: 'warning' })
                return false
            }
            this.openInfo.itemId = this.ids; //项目Id;
            this.juanOpen = true;
        },

        //关闭著录 \件\ 组卷
        closeDelDialog() {
            this.jianOpen = false //件
            this.juanOpen = false //卷
            this.projectOpen = false; //项目
            this.printOpen = false;//目录打印
            this.printOpenV = false;
            this.boxingOpen = false;
            this.hjhaoOpen=false;
            this.openInfo = ""
        },

        //著录成功
        submitDetail() {
            this.jianOpen = false;
            this.juanOpen = false //卷
            this.projectOpen = false; //项目
            this.getlistHeaderPost();
        },
        //双击列表进入详情页面
        celldblclick(row) {
            var level = "";
            var label = "";
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
                level = 0
                label = row.TITLE;
            } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
                level = 1
                label = row.TITLE;
            } else { //项目
                level = 3
                label = row.XMMC;

            }
            this.celldbData = {
                id: row.ID,
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                sub_table_name: this.queryParams.sub_table_name,
                label: this.queryParams.label,
                level: level,
                ifSub_table_name: this.queryParams.sub_table_name,
                isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                tableHeaderList: this.tableHeaderList
            }
            this.$nextTick(() => {
                if (this.subStr == "F") {  //F 进入件详情
                    this.jianDetailsOpen = true;
                } else { //进入卷详情 和项目详情
                    this.juanDetailsOpen = true
                }
            })
        },
        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.juanDetailsOpen = false;
        },

        //排序
        sortChange(val) {
            // console.log(val, "ksdfjkl")
            this.queryParams.order = val;
            // console.log(this.queryParams, "+++")
            this.getlistPost();
        },
        //退回
        tuihuiTap(e) {
            if (this.ids != undefined && !this.multiple) {
                // 项目下退回卷
                if (e == 1) {
                    tuihuiAnJuan({
                        categoryId: this.queryParams.categoryId,
                        ids: this.ids
                    }).then(res => {
                        if (res.code = "200") {
                            this.$modal.msgSuccess("退回成功");
                            this.getlistPost();
                        }
                    })
                } else {
                    tuihui({
                        categoryId: this.queryParams.categoryId,
                        ids: this.ids
                    }).then(res => {
                        if (res.code = "200") {
                            this.$modal.msgSuccess("退回成功");
                            this.getlistPost();
                        }

                    })
                }
            } else {
                this.$message({ message: '请选择退回的数据哦', type: 'warning' })
                return false
            }
        },
        //添加移交单
        addTransferOrderTap() {
            if (this.ids != undefined && !this.multiple) {
                this.$modal.confirm('是否确认添加所选数据项到移交单？').then(() => {
                    console.log("addHandOverDa")
                    addHandOverDa({
                        categoryId: this.queryParams.categoryId,
                        ids: this.ids,
                    }).then(res => {
                        if (res.code == "200") {
                            if (res.msg != '') {
                                this.$modal.msgSuccess(res.msg);
                            } else {
                                this.$modal.msgSuccess("添加成功");
                            }
                        }

                        this.getlistPost();
                    })

                }).catch(() => { });
            } else {
                this.$message({ message: '请选择要添加移交单的数据哦', type: 'warning' })
            }
        },
        //打印目录
        // printTap() {
        //     this.printList = [];
        //     if (this.ids != undefined && !this.multiple) {
        //         this.printOpen = true
        //         var idsData = this.ids.split(",")
        //         for (var i in this.tableData) {
        //             for (var j in idsData) {
        //                 if (this.tableData[i].ID == idsData[j]) {
        //                     this.printList.push(this.tableData[i])
        //                 }
        //             }
        //         }
        //     } else {
        //         this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
        //     }
        // },

        printTap(val) {
            var that = this;
            var data = [];

            if (this.ids != undefined && !this.multiple) {
                console.log(val, "000000000000000")
                if (val == '1') {
                    var nowtype = ''
                    var needtype = ''
                    var sub_table_name = ''
                    if (getLastIndexOf(this.queryParams.sub_table_name) == "V") {
                        needtype = "f"
                        nowtype = 'v',
                            sub_table_name = this.categoryInfo.fileTableName
                    } else {
                        needtype = "v"
                        nowtype = 'x'
                        sub_table_name = this.categoryInfo.folderTableName
                    }
                    /**点击树节点,获取table表头数据 */
                    getthbytreenodeHeaderList({
                        categoryId: this.queryParams.categoryId,
                        menuId: this.queryParams.menuId,
                        subTableName: this.categoryInfo.fileTableName
                    }
                    ).then(response => {

                        var fields = []
                        for (var i in response.rows) {
                            fields.push(response.rows[i].FIELD_NAME)
                        }
                        /** 点击树节点,获取table数据*/
                        getmultipleInfo({
                            categoryId: this.queryParams.categoryId,
                            nowtype: nowtype,
                            needtype: needtype,
                            ids: this.ids.split(","),
                            fields: fields.toString(),
                            menuId: this.menuId
                        }).then(res => {
                            getlistbytreenodeList(this.queryParams).then(response => {
                                var printTableData = response.rows;
                                this.getPrintList(res.data, sub_table_name, val, printTableData)
                            });
                        })
                    });
                } else {
                    getlistbytreenodeList(this.queryParams).then(response => {
                        var printTableData = response.rows;
                        this.getPrintList(printTableData, this.queryParams.sub_table_name, val)
                    });
                }
            } else {
                this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            }
        },


        //处理好的打印数据方法
        getPrintList(printTableData, sub_table_name, val, data2) {
            var that = this;
            var data = [];
            this.printList = [];
            var idsData = this.ids.split(",")
            for (var i in this.tableHeaderList) {
                if (this.tableHeaderList[i].SHOWTYPE == 5) {
                    for (var j in printTableData) {
                        for (var x in this.dictList[this.tableHeaderList[i].FIELD_NAME]) {
                            if (printTableData[j][this.tableHeaderList[i].FIELD_NAME] == this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictValue) {
                                printTableData[j][this.tableHeaderList[i].FIELD_NAME] = this.dictList[this.tableHeaderList[i].FIELD_NAME][x].dictLabel
                            }
                        }
                    }
                }
            }
            if (val == 1) {
                var datalist = ['data1', 'data2']
                var printList = [];
                for (var c in data2) {
                    for (var k in idsData) {
                        if (data2[c].ID == idsData[k]) {
                            printList.push(data2[c])
                        }
                    }
                }
                data = [{ data: printTableData }, { data: printList }];
            } else {
                var printList = [];
                for (var c in printTableData) {
                    for (var k in idsData) {
                        if (printTableData[c].ID == idsData[k]) {
                            printList.push(printTableData[c])
                        }
                    }
                }
                data = [{ data: printList }];
                var datalist = ['data']
            }
            geturl({
                categoryId: this.queryParams.categoryId,
                menuId: this.queryParams.menuId,
                type: getLastIndexOf(sub_table_name),
                data: JSON.stringify(data),
                datalist: JSON.stringify(datalist)
            }).then(res => {
                if (res.data.result == "fail") {
                    this.$message({ message: res.data.msg, type: 'warning' })
                } else {
                    window.open(res.data.url);
                }


            })
        },

        //封面打印  备考表打印

        printDyTap(val) {
            var that = this;
            var data = [];
            var name = "";
            // if (this.ids != undefined && !this.multiple) {

            var nowtype = ''
            var needtype = ''
            var sub_table_name = ''
            console.log(this.queryParams.sub_table_name)
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {
                sub_table_name = "F"
            } else {
                sub_table_name = "V"
            }
            var datalist = ['data']
            // if (getLastIndexOf(this.queryParams.sub_table_name) == "V"&&getLastIndexOf(this.queryParams.sub_table_name) == "X") {
            //     // needtype = "f"
            //     // nowtype = 'v',
            //
            //     debugger;
            //             console.log("**")
            // } else {
            //     // needtype = "v"
            //     // nowtype = 'x'
            //     sub_table_name = this.categoryInfo.fileTableName
            // }
            if (val == 0) { //封面打印
                getlistbytreenodeList(this.queryParams).then(response => {
                    var printTableData = response.rows;
                    var printList = [];
                    var idsData = this.ids.split(",")
                    for (var c in printTableData) {
                        for (var k in idsData) {
                            if (printTableData[c].ID == idsData[k]) {
                                printList.push(printTableData[c])
                            }
                        }
                    }
                    data = [{ data: printList }];
                    name = "FM"
                    geturl({
                        menuId: this.queryParams.menuId,
                        type: sub_table_name,
                        data: JSON.stringify(data),
                        name: name,
                        datalist: JSON.stringify(datalist)
                    }).then(res => {

                        if (res.data.result == "fail") {
                            this.$message({ message: res.data.msg, type: 'warning' })
                        } else {
                            window.open(res.data.url);
                        }
                    })
                });

            } else if (val == 1) {
                name = "BKB"  //备考表打印
                getbkbdata({
                    menuId: this.queryParams.menuId,
                    type: name,
                    categoryId: this.queryParams.categoryId
                }).then(res => {
                    console.log(res, "+++++++++++++")
                    geturl({
                        categoryId: this.queryParams.categoryId,
                        menuId: this.queryParams.menuId,
                        type: name,
                        data: res.msg,
                        datalist: JSON.stringify(datalist)
                    }).then(res1 => {

                        if (res1.data.result == "fail") {
                            this.$message({ message: res1.data.msg, type: 'warning' })
                        } else {
                            window.open(res1.data.url);
                        }


                    })
                }).catch(res => {

                })


            } else if (val == 2) {
                getlistbytreenodeList(this.queryParams).then(response => {
                    var printTableData = response.rows;
                    var printList = [];
                    var idsData = this.ids.split(",")
                    for (var c in printTableData) {
                        for (var k in idsData) {
                            if (printTableData[c].ID == idsData[k]) {
                                printList.push(printTableData[c])
                            }
                        }
                    }
                    data = [{ data: printList }];
                    name = "HJ"
                    geturl({
                        categoryId: this.queryParams.categoryId,
                        menuId: this.queryParams.menuId,
                        type: name,
                        data: JSON.stringify(data),
                        datalist: JSON.stringify(datalist)
                    }).then(res => {
                        if (res.data.result == "fail") {
                            this.$message({ message: res.data.msg, type: 'warning' })
                        } else {
                            window.open(res.data.url);
                        }
                    })
                });
            }







            // /**点击树节点,获取table表头数据 */
            // getthbytreenodeHeaderList({
            //     categoryId: this.queryParams.categoryId,
            //     menuId: this.queryParams.menuId,
            //     subTableName: this.categoryInfo.fileTableName
            // }
            // ).then(response => {

            //     var fields = []
            //     for (var i in response.rows) {
            //         fields.push(response.rows[i].FIELD_NAME)
            //     }
            //     /** 点击树节点,获取table数据*/
            //     getmultipleInfo({
            //         categoryId: this.queryParams.categoryId,
            //         nowtype: nowtype,
            //         needtype: needtype,
            //         ids: this.ids.split(","),
            //         fields: fields.toString()
            //     }).then(res => {
            //         console.log(res.data, "++++++2222222222222222++++++")

            //         this.getPrintList(res.data, sub_table_name, val)
            //     })
            // });



            // } else {
            //     this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            // }
        },
        //装盒
        boxingTap() {
            var siTypeText = ""
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {
                this.boxType = "0"  //件
                siTypeText = '件'

            } else {
                this.boxType = "1" //卷
                siTypeText = '案卷'
            }



            if (this.ids != undefined && !this.multiple) {
                //档案门类树门类根据categoryID回显门类详情 根据 storeMode 判断是否可以装盒  storeMode==2，盒   storeMode==1，卷
                var idsJson = this.ids.split(",")
                var dataStr = [];
                for (var i in this.tableData) {
                    for (var j in idsJson) {
                        if (this.tableData[i].ID == idsJson[j]) {
                            dataStr.push(this.tableData[i])
                        }
                    }
                }
                this.dataStr = dataStr;
                if (this.categoryInfo.storeMode == 2) {
                    //判断是否已经装过盒
                    getFlag({
                        daIds: this.ids,
                        type: 0     // // 0是装盒，1取消装盒
                    }).then(res => {
                        // console.log(res, "jfkdsjfkdlsfjklsdjf")
                        if (res.data == false) {
                            this.$message({ message: '选择的档案已经装盒完成或者包含已装盒的档案', type: 'warning' })
                        } else {
                            //装盒验证是否有装盒条件    排件号不一致不能装盒  详情
                            isPermit({
                                categoryId: this.queryParams.categoryId,
                                ids: this.ids,
                                type: this.boxType
                            }).then(res => {
                                //  isPermit==false ,  "拍案卷号或者拍件号不一致不能装盒"  isPermit==true  可以装盒
                                // console.log(res.data, "++++")
                                this.permitInfo = res.data
                                if (res.data.isPermit) {
                                    this.boxingOpen = true;
                                } else {
                                    this.$message({ message: '选择的' + siTypeText + '的排' + siTypeText + '号规则不一致，请选择排' + siTypeText + '号规则一致的' + siTypeText + '装盒', type: 'warning' })
                                }

                            })
                        }
                    })

                } else {
                    this.$message({ message: '当前门类不是按盒上架的哦', type: 'warning' })
                }


            } else {
                this.$message({ message: '请选择要装盒的档案哦', type: 'warning' })
            }
        },

        //装盒成功
        submitTap() {
            this.boxingOpen = false;
            this.getlistPost();
        },

        //取消装盒
        quxiaoBoxingTap() {
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {
                this.boxType = "0"  //件
            } else {
                this.boxType = "1" //卷
            }
            if (this.ids != undefined && !this.multiple) {
                //判断是否已经装过盒   如果  true  意思装过盒了  可以取消装
                getFlag({
                    daIds: this.ids,
                    type: 1     // // 0是装盒，1取消装盒
                }).then(res => {
                    // console.log(res, "jfkdsjfkdlsfjklsdjf")
                    if (res.data == true) {
                        this.$modal.confirm('是否确认所选数据项取消装盒？').then(() => {
                            cancelBox({
                                categoryId: this.queryParams.categoryId,
                                ids: this.ids,
                                type: this.boxType,
                            }).then(res => {
                                this.$modal.msgSuccess("取消成功");
                                this.getlistPost();
                            })

                        }).catch(() => { });
                    } else {
                        this.$message({ message: '选择的档案没有装过盒或者包含没装过盒的档案', type: 'warning' })
                    }
                })
            } else {
                this.$message({ message: '请选择要取消装盒的档案哦', type: 'warning' })
            }
        },

        //卷内目录打印
        printVFTap() {
            if (this.ids != undefined && !this.multiple) {

                var nowtype = ''
                var needtype = ''
                var sub_table_name = ''
                if (getLastIndexOf(this.queryParams.sub_table_name) == "V") {
                    needtype = "f"
                    nowtype = 'v',
                        sub_table_name = this.categoryInfo.fileTableName
                } else {
                    needtype = "v"
                    nowtype = 'x'
                    sub_table_name = this.categoryInfo.folderTableName
                }

                getthbytreenodeHeaderList({
                    categoryId: this.queryParams.categoryId,
                    menuId: this.queryParams.menuId,
                    subTableName: sub_table_name
                }
                ).then(response => {
                    this.tableHeaderListV = response.rows;
                    var fields = []
                    for (var i in response.rows) {
                        fields.push(response.rows[i].FIELD_NAME)
                    }

                    getmultipleInfo({
                        categoryId: this.queryParams.categoryId,
                        nowtype: nowtype,
                        needtype: needtype,
                        ids: this.ids.split(","),
                        fields: fields.toString()
                    }).then(res => {
                        console.log(res, "+++++")
                        this.printListV = res.data;
                        this.printOpenV = true
                    })

                });


            } else {
                this.$message({ message: '请选择要打印的数据哦', type: 'warning' })
            }

        },

        // 添加到指导单
        handleGuidanceTap() {
            if (this.ids == undefined || this.ids.length == 0) {
                this.$message({ message: '请选择要添加到指导单数据哦', type: 'warning' })
                return false
            }
            var type = ''
            if (this.subStr == "F") {  //F 件
                type = 0
            } else if (this.subStr == "V") { //卷
                type = 1
            }
            this.form = []
            var idsData = this.ids.split(",");
            for (var i in idsData) {
                this.form.push({
                    daId: idsData[i],
                    subTableName: this.queryParams.sub_table_name,
                    categoryId: this.queryParams.categoryId,
                    source: '1',
                    type: type
                })
            }
            supervisionDa1(this.form).then(response => {
                this.getlistPost()
                this.$modal.msgSuccess('添加成功')
            })
        },

        handleSpecalTap() {
            if (this.ids == undefined || this.ids.length == 0) {
                this.$message({ message: '请选择要添加到档案资源的数据哦', type: 'warning' })
                return false
            }
            var type = "";
            if (getLastIndexOf(this.queryParams.sub_table_name) == "F") {  //F 件
                type = 0
            } else if (getLastIndexOf(this.queryParams.sub_table_name) == "V") { //卷
                type = 1
            } else { //项目
                type = 3
            }
            this.form = this.detail.map(item => {
                return {
                    subTableName: this.queryParams.sub_table_name,
                    daDh: item.daDh,
                    daBgqx: item.daBgqx,
                    daType: type,
                    daMj: item.daMj,
                    daId: item.daId,
                    typeState: '1',
                    daTitle: item.daTitle,
                    daNd: item.daNd,
                    categoryId: this.queryParams.categoryId
                }
            })
            addPerson(this.form).then(response => {
                this.getlistPost()
                this.$modal.msgSuccess('添加成功')
            })
        },

        // 导出
        handleExport() {
            let type = "";
            if (this.subStr == "F") {  //F 件
                type = 0
            } else if (this.subStr == "V") { //卷
                type = 1
            } else { //项目
                type = 3
            }
            var data = {
                state: this.queryParams.state,
                categoryId: this.queryParams.categoryId,
                subTableName: this.queryParams.sub_table_name,
                menuId: this.queryParams.menuId,
                propertyName: this.queryParams.propertyName,
                propertyValue: this.queryParams.propertyValue,
                order: this.queryParams.order,
                ids: this.ids,
                searchcolumn: this.queryParams.searchcolumn,
                type: type
            }
            data = JSON.stringify(data);
            let dataParams = {
                data1: data,
                pageSize: this.queryParams.pageSize,
                pageNum: this.queryParams.pageNum
            }
            this.download('/archive/wjzl/export', {
                ...dataParams
            }, `dagl_${new Date().getTime()}.xlsx`)
        },



        //打包功能
        zipTap() {

            var that=this;

            if (!this.multiple) {

                this.$modal.loading("打包中...")



            let type = "";
            if (this.subStr == "F") {  //F 件
                type = 0
            } else if (this.subStr == "V") { //卷
                type = 1
            } else { //项目
                type = 3
            }


                pack({
                    categoryId: this.queryParams.categoryId,
                    ids: this.ids,
                    type: type
                }
                ).then(res => {
                    console.log(res)
                })


                setTimeout(function(){
                    that.$modal.closeLoading();
                },1000)

            } else {
                this.$message({ message: '请选择打包的数据哦', type: 'warning' })
                return false
            }
        },
              //互见号功能
              HJhaoTap() {
            if(!this.single){
                this.hjhaoOpen=true

            }else{
                this.$message({ message: '请选择一条档案数据哦', type: 'warning' })
            }
        },

    }
}
</script>
